From 6fd99e5b8291d815544ea2dd67e412749e70d968 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Fri, 15 Sep 2017 17:15:11 +0100
Subject: [PATCH] =?UTF-8?q?Add=20=C2=AB=20Parent=20page=20link=20to=20subp?=
 =?UTF-8?q?ages?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Changelog.md          |  2 ++
 build/index.php       | 29 ++++++++++++++++++++++++++---
 core.php              | 13 +++++++++++++
 module_index.json     |  6 +++---
 modules/page-view.php |  9 +++++++--
 theme_default.css     |  8 +++++++-
 6 files changed, 58 insertions(+), 9 deletions(-)

diff --git a/Changelog.md b/Changelog.md
index 8e7a2ee..3895795 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -8,6 +8,8 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
      - Added a new statistics engine, which you can add your own statistic calculators to with `statistic_add`
      - Added action `stats` to view the calculated statisics
      - Statistics are automagically recalculated every day - this can be controlled with `stats_update_interval` and `stats_update_processingtime`
+ - Added new "« Parent Page" to subpages so that you can easily visit their parent pages
+ - Added new `get_page_parent($pagename)` API method.
 
 ### Fixed
  - Fixed invalid opensearch description.
diff --git a/build/index.php b/build/index.php
index 52e03e0..5829ad7 100644
--- a/build/index.php
+++ b/build/index.php
@@ -296,7 +296,13 @@ textarea ~ input[type=submit] { margin: 0.5rem 0; padding: 0.5rem; font-weight:
 .editform input[type=text] { width: calc(100% - 0.3rem); box-sizing: border-box; }
 input.edit-page-button[type='submit'] { width: 49.5%; box-sizing: border-box; }
 .preview-message { text-align: center; }
-.jump-to-comments { position: relative; top: -2.5em; display: block; text-align: right; pointer-events: none; }
+@media (min-width: 800px) {
+	.jump-to-comments { position: absolute; top: 3.5em; right: 2em; display: block; text-align: right; pointer-events: none; }
+}
+@media (max-width: 799px) {
+	.jump-to-comments { display: inline-block; }
+	.link-parent-page { display: inline-block; }
+}
 .jump-to-comments > a { pointer-events: all; }
 
 .file-gallery { margin: 0.5em; padding: 0.5em; list-style-type: none; }
@@ -587,6 +593,18 @@ function glob_recursive($pattern, $flags = 0)
 	return $files;
 }
 
+/**
+ * Gets the name of the parent page to the specified page.
+ * @param  string		$pagename	The child page to get the parent
+ * 								page name for.
+ * @return string|bool	
+ */
+function get_page_parent($pagename) {
+	if(mb_strpos($pagename, "/") === false)
+		return false;
+	return mb_substr($pagename, 0, mb_strrpos($pagename, "/"));
+}
+
 /**
  * Gets a list of all the sub pages of the current page.
  * @param	object	$pageindex	The pageindex to use to search.
@@ -6776,7 +6794,7 @@ register_module([
 
 register_module([
 	"name" => "Page viewer",
-	"version" => "0.16.6",
+	"version" => "0.16.7",
 	"author" => "Starbeamrainbowlabs",
 	"description" => "Allows you to view pages. You really should include this one.",
 	"id" => "page-view",
@@ -6873,9 +6891,14 @@ register_module([
 				$content .= "<p class='revision-note'><em>(Revision saved by {$env->history->revision_data->editor} " . render_timestamp($env->history->revision_data->timestamp) . ". <a href='?page=" . rawurlencode($env->page) . "'>Jump to the current revision</a> or see a <a href='?action=history&page=" . rawurlencode($env->page) . "'>list of all revisions</a> for this page.)</em></p>\n";
 			}
 			
+			// Add a visit parent page link if we're a subpage
+			if(get_page_parent($env->page) !== false) {
+				$content .= "<p class='link-parent-page'><em><a href='?action=view&page=" . rawurlencode(get_page_parent($env->page)) . "'>&laquo; " . htmlentities(get_page_parent($env->page)) . "</a></em></p>\n";
+			}
+			
 			// Add an extra message if the requester was redirected from another page
 			if(isset($_GET["redirected_from"]))
-				$content .= "<p><em>Redirected from <a href='?page=" . rawurlencode($_GET["redirected_from"]) . "&redirect=no'>" . $_GET["redirected_from"] . "</a>.</em></p>";
+				$content .= "<p><em>Redirected from <a href='?page=" . rawurlencode($_GET["redirected_from"]) . "&redirect=no'>" . $_GET["redirected_from"] . "</a>.</em></p>\n";
 			
 			$parsing_start = microtime(true);
 			
diff --git a/core.php b/core.php
index f7a5a85..b51584e 100644
--- a/core.php
+++ b/core.php
@@ -226,6 +226,19 @@ function glob_recursive($pattern, $flags = 0)
 	return $files;
 }
 
+/**
+ * Gets the name of the parent page to the specified page.
+ * @since 0.15
+ * @param  string		$pagename	The child page to get the parent
+ * 									page name for.
+ * @return string|bool
+ */
+function get_page_parent($pagename) {
+	if(mb_strpos($pagename, "/") === false)
+		return false;
+	return mb_substr($pagename, 0, mb_strrpos($pagename, "/"));
+}
+
 /**
  * Gets a list of all the sub pages of the current page.
  * @param	object	$pageindex	The pageindex to use to search.
diff --git a/module_index.json b/module_index.json
index 706eb86..3098b05 100755
--- a/module_index.json
+++ b/module_index.json
@@ -59,7 +59,7 @@
         "author": "Starbeamrainbowlabs",
         "description": "Adds threaded comments to the bottom of every page.",
         "id": "feature-comments",
-        "lastupdate": 1497799232,
+        "lastupdate": 1505489462,
         "optional": false
     },
     {
@@ -244,11 +244,11 @@
     },
     {
         "name": "Page viewer",
-        "version": "0.16.6",
+        "version": "0.16.7",
         "author": "Starbeamrainbowlabs",
         "description": "Allows you to view pages. You really should include this one.",
         "id": "page-view",
-        "lastupdate": 1498646088,
+        "lastupdate": 1505491607,
         "optional": false
     },
     {
diff --git a/modules/page-view.php b/modules/page-view.php
index ebb817c..8c08ce3 100644
--- a/modules/page-view.php
+++ b/modules/page-view.php
@@ -1,7 +1,7 @@
 <?php
 register_module([
 	"name" => "Page viewer",
-	"version" => "0.16.6",
+	"version" => "0.16.7",
 	"author" => "Starbeamrainbowlabs",
 	"description" => "Allows you to view pages. You really should include this one.",
 	"id" => "page-view",
@@ -98,9 +98,14 @@ register_module([
 				$content .= "<p class='revision-note'><em>(Revision saved by {$env->history->revision_data->editor} " . render_timestamp($env->history->revision_data->timestamp) . ". <a href='?page=" . rawurlencode($env->page) . "'>Jump to the current revision</a> or see a <a href='?action=history&page=" . rawurlencode($env->page) . "'>list of all revisions</a> for this page.)</em></p>\n";
 			}
 			
+			// Add a visit parent page link if we're a subpage
+			if(get_page_parent($env->page) !== false) {
+				$content .= "<p class='link-parent-page'><em><a href='?action=view&page=" . rawurlencode(get_page_parent($env->page)) . "'>&laquo; " . htmlentities(get_page_parent($env->page)) . "</a></em></p>\n";
+			}
+			
 			// Add an extra message if the requester was redirected from another page
 			if(isset($_GET["redirected_from"]))
-				$content .= "<p><em>Redirected from <a href='?page=" . rawurlencode($_GET["redirected_from"]) . "&redirect=no'>" . $_GET["redirected_from"] . "</a>.</em></p>";
+				$content .= "<p><em>Redirected from <a href='?page=" . rawurlencode($_GET["redirected_from"]) . "&redirect=no'>" . $_GET["redirected_from"] . "</a>.</em></p>\n";
 			
 			$parsing_start = microtime(true);
 			
diff --git a/theme_default.css b/theme_default.css
index 68d21aa..0ee703c 100644
--- a/theme_default.css
+++ b/theme_default.css
@@ -75,7 +75,13 @@ textarea ~ input[type=submit] { margin: 0.5rem 0; padding: 0.5rem; font-weight:
 .editform input[type=text] { width: calc(100% - 0.3rem); box-sizing: border-box; }
 input.edit-page-button[type='submit'] { width: 49.5%; box-sizing: border-box; }
 .preview-message { text-align: center; }
-.jump-to-comments { position: relative; top: -2.5em; display: block; text-align: right; pointer-events: none; }
+@media (min-width: 800px) {
+	.jump-to-comments { position: absolute; top: 3.5em; right: 2em; display: block; text-align: right; pointer-events: none; }
+}
+@media (max-width: 799px) {
+	.jump-to-comments { display: inline-block; }
+	.link-parent-page { display: inline-block; }
+}
 .jump-to-comments > a { pointer-events: all; }
 
 .file-gallery { margin: 0.5em; padding: 0.5em; list-style-type: none; }
